<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/10/29
  Time: 13:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<select name="city" id="city">
    <option value="">无</option>
</select>

</body>

<script src="js/jquery-1.12.4.min.js"></script>

<script>

   /* var citys = [{"id":1,"name":"石家庄","zhi":"shijiazhuang"},
        {"id":2,"name":"北京","zhi":"beijing"},
        {"id":3,"name":"上海2","zhi":"shanghai"},
        {"id":4,"name":"纽约","zhi":"newYork"}];*/

   //var citys ='[{"id":1,"name":"哈尔滨","zhi":"haerbin"},{"id":2,"name":"沈阳","zhi":"shenyang"},{"id":3,"name":"吉林","zhi":"jilin"}]'

    aaa();
    //1 告诉前台jsp  就把后台返回的数据当成json串处理  dataType:"json",
   // 2  让 后台告诉前台, 返回的是json串  response.setContentType("application/json;charset=UTF-8");
    function aaa() {


        $.ajax({
            url:"${pageContext.request.contextPath}/cc",
            method:"post",
            dataType:"json",
            success:function (citys) {
                console.log(citys.length)
                for(var i = 0;i<citys.length;i++){
                    $("#city").append('<option value="'+citys[i].zhi+'">'+citys[i].name+'</option>')
                }
            }
        });



    }


</script>
</html>
